﻿(function ($) {
    // 改变默认配置
    var d = $.dialog.defaults;
    // 预缓存皮肤，数组第一个为默认皮肤
    d.skin = ['facebook', 'aero', 'chrome', 'default'];
    d.plus = true;
    // 是否开启锁屏
    d.lock = true;
    // 指定超过此面积的对话框拖动的时候用替身
    //d.showTemp = 0;
})(art);
function itieba(link, title, content, videoID) {
    if (curUserID <= 0 || curUserID == "") {
        art.dialog.alert("您未登录，转帖将不会产生玉米收入!");
    } else {
        var iRet = PUBAjaxClass.LinkVideo(curUserID, videoID).value;
    }
    var itieba_share = 'http://tieba.baidu.com/i/sys/share?link=' + link + '&type=video&title=' + title + '&content=' + content;
    if (!window.open(itieba_share, 'itieba', 'toolbar=0,resizable=1,scrollbars=yes,status=1,width=626,height=436')) {
        location.href = itieba_share;
    }
}
function PlayVideo(id, title) {
    art.dialog.open('http://www.baomihua.com/manage/playvideo.aspx?vid=' + id, {
        id: 'playVideo',
        title: '正在播放：' + title,
        lock: true,
        skin: 'aero',
        width: 588,
        height: 487,
        esc: false
    });
}
function ShowBlog(id, title) {
    art.dialog.open('http://www.baomihua.com/manage/blogshow.aspx?blogid=' + id, {
        id: 'ShowBlog',
        title: title,
        lock: true,
        skin: 'aero',
        width: 588,
        height: 487,
        esc: false
    });
}
function showImg(url) {
    var tempHtml = "<img src=\"" + url + "\" />";
    art.dialog({
        id: 'showImg',
        title: '图片展示',
        content: tempHtml,
        lock: true,
        skin: 'aero',
        width: 588,
        height: 487,
        esc: false
    });
}
/*弹出不同类型的消息 
参数说明：
type消息框类型：1-成功 2-错误 3-提示
str消息内容
*/
function alertMessage(type, str) {
    var iconStr = "";
    var timeStr = 60;
    switch (type) {
        case 1:
            iconStr = "succeed";
            timeStr = 10;
            break;
        case 2:
            iconStr = "error";
            break;
        case 3:
            iconStr = "alert";
            break;
    }
    art.dialog({
        content: str,
        title: '操作提示',
        lock: true,
        time: timeStr,
        icon: iconStr,
        skin: 'aero'
    });
}

/*
返回顶部
*/
function goto_top() {
    document.documentElement.scrollTop = 0;   //兼容firefox
    document.body.scrollTop = 0;
}
//判断是否为中文
function isChinese(str) {
    var lst = /[^\u4E00-\u9FA5]/;
    return !lst.test(str);
}
//返回字符串的长度
function GetStringLength(str) {
    var strLength = 0;
    for (i = 0; i < str.length; i++) {
        if (isChinese(str.charAt(i)) == true) {
            strLength = strLength + 2;
        }
        else {
            strLength = strLength + 1;
        }
    }
    return strLength;
}
function GetQueryString(name, value) {
    var zz = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var strurl = window.location.search.substr(1).match(zz);
    if (null != strurl) {
        return strurl[2];
    } else {
        return value;
    }
}
function AjaxZhuanTie(videoID) {
    if (curUserID <= 0 || curUserID == "") {
        art.dialog.alert("您未登录，转帖将不会产生玉米收入!");
    } else {
        var iRet = PUBAjaxClass.LinkVideo(curUserID, videoID).value;
    }
    //window.open(encodeURI(linkUrl));

}
function AjaxDelFriend(userID, friendID) {
    if (userID <= 0 || friendID <= 0 || friendID == "" || userID == "") {
        art.dialog.alert("你未登录，请先登录再删除好友！");
        return;
    }
    var iRet = PUBAjaxClass.DelUserFriend(userID, friendID).value;
    if (iRet > 0) {
        art.dialog({
            content: "删除成功！",
            skin: 'facebook',
            lock: false,
            effect: false,
            border: false
        }).time(1);
        var type = $("#hidType").val();
        if (type == "1") {
            var count = PUBAjaxClass.DeleteUserFollow_NoteBook_Tool(userID, friendID).value;
            var content = ShowWeiboList(1, $("#hidUserID").val(), $("#hidTopicID").val());
            $('#viewContent').empty();
            content = $(content).prependTo($('#viewContent'));
            Ucenter.bTinyblog.init(content);
        }
    }
}
function AjaxAddFriend(userID, friendID) {
    if ( friendID <= 0 || friendID == "") {
        art.dialog.alert("好友ID不能为空");
        return;
    }
    $.getJSON("http://interface.baomihua.com/pubapi.asmx/AddFriend?jsoncallback=?", { uid: friendID }, function (json) {
        if (typeof (json.Result) != 'undefined') {
            iRet = json.Result;
            switch (iRet) {
                case "4":
                    art.dialog({
                        content: "他已经是你的好友了！",
                        skin: 'facebook',
                        lock: false,
                        effect: false,
                        border: false
                    }).time(1);
                    break;
                case "-9":
                    art.dialog({
                        content: "你不能成为自己的好友！",
                        skin: 'facebook',
                        lock: false,
                        effect: false,
                        border: false
                    }).time(1);
                    break;
                case "-3":
                    art.dialog({
                        content: "用户状态无效！",
                        skin: 'facebook',
                        lock: false,
                        effect: false,
                        border: false
                    }).time(1);
                    break;
                case "-2":
                    art.dialog({
                        content: "你未登录，请先登录再添加好友！",
                        skin: 'facebook',
                        lock: false,
                        effect: false,
                        border: false
                    }).time(1);
                    break;
                case "-1","0":
                    art.dialog({
                        content: "出现错误，请稍后再试！",
                        icon: 'error',
                        skin: 'aero',
                        yesFn: true,
                        width: 200,
                        height: 60
                    }).time(1);
                    break;
                case "1":
                    art.dialog({
                        content: "加好友成功",
                        skin: 'facebook',
                        lock: false,
                        effect: false,
                        border: false
                    }).time(1);
                    var type = $("#hidType").val();
                    if (type == "1") {
                        var ret = PUBAjaxClass.GetUserFollow_NoteBook_Tool(userID, friendID).value;
                        var content = ShowWeiboList(1, $("#hidUserID").val(), $("#hidTopicID").val());
                        $('#viewContent').empty();
                        content = $(content).prependTo($('#viewContent'));
                        Ucenter.bTinyblog.init(content);
                    }

                   
                    break;
            }
        }
    });
}

Date.prototype.format = function (format) {
    /*  

    * eg:format="YYYY-MM-dd hh:mm:ss";  
    */
    var o = {

        "M+": this.getMonth() + 1, // month  
        "d+": this.getDate(), // day  
        "h+": this.getHours(), // hour  
        "m+": this.getMinutes(), // minute  
        "s+": this.getSeconds(), // second  
        "q+": Math.floor((this.getMonth() + 3) / 3), // quarter  
        "S": this.getMilliseconds()
    }
    if (/(y+)/.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + "")
              .substr(4 - RegExp.$1.length));
    }
    for (var k in o) {

        if (new RegExp("(" + k + ")").test(format)) {

            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]

                   : ("00" + o[k]).substr(("" + o[k]).length));
        }
    }
    return format;

}
function ReprintedVedio_PUB(userID, objUserID, obj) {
    var retVal = PUBAjaxClass.LinkVideo(curUserID, obj).value;
    if (retVal == 1) {
        alertMessage(1, '视频转载成功');
        $(".view_stack div span[videoID='" + obj + "']").hide();
    } else if (retVal == 2) {
        alertMessage(3, '该视频您已转载过了');
    } else if (retVal == 0) {
        alertMessage(2, '转载失败，可能由网络问题引起，请稍后操作!');
    } else if (retVal == -1) {
        alertMessage(2, '转载失败，可能由网络问题引起，请稍后操作!');
    } else if (retVal == -9) {
        alertMessage(2, '转载失败，不能转载自己的视频!');
    }
}
function safeHtml(obj) {
    obj = obj.replace(/</g, "《").replace(/>/g, "》").replace(/java/g, "ｊａｖａ").replace(/script/g, "ｓｃｒｉｐｔ").replace(/--/g, "－－").replace(/;/g, "；").replace(/\'/g, "‘");
    return obj;
}
function receiveTask(userId, recordId, taskId, typeId) {
    var retVal = PUBAjaxClass.UserReceiveAdward(userId, recordId, taskId, typeId).value;
    if (retVal == 1) {
        window.location.reload();
    }
    else {
        alertMessage(2, '任务领取失败');
    }
}
function receiveAdward(userId, recordID, taskId, typeId) {
    var retVal = PUBAjaxClass.ReceiveAdward(userId, recordID, taskId, typeId).value;
    if (retVal == 1) {
        window.location.reload();
    }
    else {
        alertMessage(2, '奖励领取失败');
    }
}